<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <script>
    async function hello() {
      return 123
    }

    // 普通函数只要加了 async，返回值会自动变成promise
    const res = hello();


    function loadNewTodoAPI() {
      const newTodo = {
        task: '异步返回的任务',
        id: Date.now(),
        isDone: false,
      };
      console.log('开始请求');
      return new Promise((resolve) => {
        setTimeout(() => {
          console.log('请求成功，2秒后,数据返回');
          resolve(newTodo);
        }, 2000);
      });
    }

    async function fn() {
      const res = await loadNewTodoAPI()
      console.log(' res ----->  ', res);
    }

    fn()

  </script>

</body>

</html>